Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Translation: desktop-electron #3267

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

psybers
Copy link
Contributor

@psybers psybers commented Aug 15, 2024

Translation support for packages/desktop-electron.

@actual-github-bot actual-github-bot bot changed the title Translation: desktop-electron [WIP] Translation: desktop-electron Aug 15, 2024
Copy link

netlify bot commented Aug 15, 2024

Deploy Preview for actualbudget failed.

Name Link
🔨 Latest commit 8e64a7b
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6757b8c92af62700086b3d65

Copy link
Contributor

github-actions bot commented Aug 15, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 5.3 MB → 5.2 MB (-97.34 kB) -1.80%
Changeset (largest 100 files by percent change)
File Δ Size
src/components/modals/ImportTransactions.jsx 🆕 +51.69 kB 0 B → 51.69 kB
src/components/accounts/Account.jsx 🆕 +42.84 kB 0 B → 42.84 kB
src/components/modals/EditRule.jsx 🆕 +37.2 kB 0 B → 37.2 kB
src/components/select/RecurringSchedulePicker.jsx 🆕 +16.37 kB 0 B → 16.37 kB
node_modules/react-modal/lib/components/ModalPortal.js 🆕 +15.25 kB 0 B → 15.25 kB
src/components/budget/rollover/RolloverComponents.tsx 🆕 +13.45 kB 0 B → 13.45 kB
src/components/budget/report/ReportComponents.tsx 🆕 +12.58 kB 0 B → 12.58 kB
node_modules/react-modal/lib/components/Modal.js 🆕 +10.71 kB 0 B → 10.71 kB
src/components/common/Modal2.tsx 🆕 +9.26 kB 0 B → 9.26 kB
src/components/modals/GoCardlessExternalMsg.tsx 🆕 +9.03 kB 0 B → 9.03 kB
src/components/modals/EditField.jsx 🆕 +7.57 kB 0 B → 7.57 kB
src/components/budget/rollover/budgetsummary/BudgetSummary.tsx 🆕 +7.31 kB 0 B → 7.31 kB
src/components/modals/SelectLinkedAccounts.jsx 🆕 +7.17 kB 0 B → 7.17 kB
src/components/budget/report/budgetsummary/BudgetSummary.tsx 🆕 +6.74 kB 0 B → 6.74 kB
src/components/modals/MergeUnusedPayees.jsx 🆕 +6.3 kB 0 B → 6.3 kB
src/components/mobile/accounts/AccountTransactions.jsx 🆕 +6.3 kB 0 B → 6.3 kB
node_modules/react-lifecycles-compat/react-lifecycles-compat.es.js 🆕 +5.88 kB 0 B → 5.88 kB
src/components/modals/RolloverBudgetMonthMenuModal.tsx 🆕 +5.71 kB 0 B → 5.71 kB
src/components/modals/ReportBudgetMonthMenuModal.tsx 🆕 +5.55 kB 0 B → 5.55 kB
src/components/modals/LoadBackup.jsx 🆕 +5.29 kB 0 B → 5.29 kB
src/components/modals/ConfirmCategoryDelete.tsx 🆕 +4.74 kB 0 B → 4.74 kB
src/components/accounts/Reconcile.jsx 🆕 +4.59 kB 0 B → 4.59 kB
src/components/reports/Header.jsx 🆕 +4.22 kB 0 B → 4.22 kB
src/components/manager/DeleteFile.tsx 🆕 +4.15 kB 0 B → 4.15 kB
node_modules/reselect/es/index.js 🆕 +4.13 kB 0 B → 4.13 kB
src/components/modals/GoCardlessInitialise.tsx 🆕 +3.87 kB 0 B → 3.87 kB
src/components/budget/rollover/budgetsummary/TotalsList.tsx 🆕 +3.74 kB 0 B → 3.74 kB
node_modules/reselect/es/defaultMemoize.js 🆕 +3.64 kB 0 B → 3.64 kB
src/components/modals/ConfirmTransactionEdit.tsx 🆕 +3.6 kB 0 B → 3.6 kB
node_modules/react-modal/lib/helpers/ariaAppHider.js 🆕 +3.59 kB 0 B → 3.59 kB
src/components/manager/ImportActual.tsx 🆕 +3.41 kB 0 B → 3.41 kB
src/components/manager/Import.tsx 🆕 +3.38 kB 0 B → 3.38 kB
src/components/manager/ImportYNAB5.tsx 🆕 +3.03 kB 0 B → 3.03 kB
src/components/manager/ImportYNAB4.tsx 🆕 +3.01 kB 0 B → 3.01 kB
src/components/modals/SimpleFinInitialise.tsx 🆕 +2.87 kB 0 B → 2.87 kB
src/components/modals/RolloverBudgetSummaryModal.tsx 🆕 +2.81 kB 0 B → 2.81 kB
node_modules/react-modal/lib/helpers/tabbable.js 🆕 +2.79 kB 0 B → 2.79 kB
src/components/budget/rollover/budgetsummary/ToBudget.tsx 🆕 +2.65 kB 0 B → 2.65 kB
src/components/modals/RolloverBudgetMenuModal.tsx 🆕 +2.63 kB 0 B → 2.63 kB
src/components/modals/ReportBudgetMenuModal.tsx 🆕 +2.62 kB 0 B → 2.62 kB
src/components/budget/report/budgetsummary/Saved.tsx 🆕 +2.6 kB 0 B → 2.6 kB
node_modules/react-modal/lib/helpers/scopeTab.js 🆕 +2.58 kB 0 B → 2.58 kB
src/components/budget/rollover/TransferMenu.tsx 🆕 +2.42 kB 0 B → 2.42 kB
src/components/modals/RolloverBalanceMenuModal.tsx 🆕 +2.38 kB 0 B → 2.38 kB
node_modules/react-modal/lib/helpers/focusManager.js 🆕 +2.36 kB 0 B → 2.36 kB
src/components/modals/ReportBalanceMenuModal.tsx 🆕 +2.3 kB 0 B → 2.3 kB
src/components/budget/rollover/budgetsummary/ToBudgetAmount.tsx 🆕 +2.15 kB 0 B → 2.15 kB
src/components/manager/Modals.jsx 🆕 +2.14 kB 0 B → 2.14 kB
src/components/budget/rollover/CoverMenu.tsx 🆕 +2.13 kB 0 B → 2.13 kB
src/components/modals/ConfirmUnlinkAccount.tsx 🆕 +2.1 kB 0 B → 2.1 kB
node_modules/react-modal/lib/helpers/bodyTrap.js 🆕 +2.01 kB 0 B → 2.01 kB
src/components/modals/ConfirmTransactionDelete.tsx 🆕 +1.91 kB 0 B → 1.91 kB
home/runner/work/actual/actual/packages/loot-core/src/client/query-hooks.tsx 🆕 +1.73 kB 0 B → 1.73 kB
node_modules/react-modal/lib/helpers/classList.js 🆕 +1.71 kB 0 B → 1.71 kB
src/components/budget/rollover/budgetsummary/BudgetMonthMenu.tsx 🆕 +1.69 kB 0 B → 1.69 kB
node_modules/react-modal/lib/helpers/portalOpenInstances.js 🆕 +1.68 kB 0 B → 1.68 kB
src/components/budget/rollover/HoldMenu.tsx 🆕 +1.65 kB 0 B → 1.65 kB
src/components/budget/report/budgetsummary/BudgetTotal.tsx 🆕 +1.61 kB 0 B → 1.61 kB
src/components/modals/ReportBudgetSummaryModal.tsx 🆕 +1.57 kB 0 B → 1.57 kB
src/components/budget/report/budgetsummary/BudgetMonthMenu.tsx 🆕 +1.53 kB 0 B → 1.53 kB
src/components/mobile/accounts/Account.jsx 🆕 +1.47 kB 0 B → 1.47 kB
src/components/budget/rollover/BalanceMovementMenu.tsx 🆕 +1.39 kB 0 B → 1.39 kB
src/components/budget/report/BudgetMenu.tsx 🆕 +1.38 kB 0 B → 1.38 kB
src/components/modals/countries.ts 🆕 +1.34 kB 0 B → 1.34 kB
src/components/budget/rollover/BudgetMenu.tsx 🆕 +1.34 kB 0 B → 1.34 kB
src/components/budget/rollover/budgetsummary/ToBudgetMenu.tsx 🆕 +1.31 kB 0 B → 1.31 kB
src/components/budget/rollover/BalanceMenu.tsx 🆕 +1.06 kB 0 B → 1.06 kB
src/components/modals/RolloverToBudgetMenuModal.tsx 🆕 +953 B 0 B → 953 B
home/runner/work/actual/actual/packages/loot-core/src/client/update-notification.ts 🆕 +889 B 0 B → 889 B
src/components/budget/rollover/RolloverContext.tsx 🆕 +801 B 0 B → 801 B
src/components/budget/report/budgetsummary/PieProgress.tsx 🆕 +755 B 0 B → 755 B
node_modules/exenv/index.js 🆕 +751 B 0 B → 751 B
node_modules/react-modal/lib/helpers/safeHTMLElement.js 🆕 +682 B 0 B → 682 B
src/components/budget/report/budgetsummary/ExpenseProgress.tsx 🆕 +682 B 0 B → 682 B
src/components/budget/report/BalanceMenu.tsx 🆕 +631 B 0 B → 631 B
src/hooks/useSetThemeColor.ts 🆕 +628 B 0 B → 628 B
src/components/budget/report/budgetsummary/IncomeProgress.tsx 🆕 +575 B 0 B → 575 B
src/components/budget/report/ReportContext.tsx 🆕 +493 B 0 B → 493 B
node_modules/react-modal/lib/index.js 🆕 +467 B 0 B → 467 B
home/runner/work/actual/actual/packages/loot-core/src/client/selectors.ts 🆕 +353 B 0 B → 353 B
src/components/budget/report/budgetsummary/ExpenseTotal.tsx 🆕 +299 B 0 B → 299 B
src/components/budget/report/budgetsummary/IncomeTotal.tsx 🆕 +295 B 0 B → 295 B
src/components/budget/report/budgetsummary/fraction.ts 🆕 +135 B 0 B → 135 B
node_modules/react-lifecycles-compat/react-lifecycles-compat.es.js?commonjs-proxy 🆕 +80 B 0 B → 80 B
src/hooks/useLocalPrefs.ts 🆕 +80 B 0 B → 80 B
src/components/rules/SchedulesQuery.ts 🆕 +70 B 0 B → 70 B
node_modules/warning/warning.js 🆕 +54 B 0 B → 54 B
node_modules/react-modal/lib/components/ModalPortal.js?commonjs-module 🆕 +32 B 0 B → 32 B
node_modules/react-modal/lib/helpers/portalOpenInstances.js?commonjs-exports 🆕 +31 B 0 B → 31 B
node_modules/react-modal/lib/helpers/tabbable.js?commonjs-module 🆕 +29 B 0 B → 29 B
node_modules/react-modal/lib/helpers/scopeTab.js?commonjs-module 🆕 +29 B 0 B → 29 B
node_modules/exenv/index.js?commonjs-module 🆕 +26 B 0 B → 26 B
node_modules/react-modal/lib/helpers/safeHTMLElement.js?commonjs-exports 🆕 +25 B 0 B → 25 B
node_modules/react-modal/lib/index.js?commonjs-module 🆕 +24 B 0 B → 24 B
node_modules/react-modal/lib/helpers/ariaAppHider.js?commonjs-exports 🆕 +24 B 0 B → 24 B
node_modules/react-modal/lib/helpers/focusManager.js?commonjs-exports 🆕 +22 B 0 B → 22 B
node_modules/react-modal/lib/helpers/bodyTrap.js?commonjs-exports 🆕 +20 B 0 B → 20 B
node_modules/react-modal/lib/helpers/classList.js?commonjs-exports 🆕 +19 B 0 B → 19 B
node_modules/react-modal/lib/components/Modal.js?commonjs-exports 🆕 +17 B 0 B → 17 B
home/runner/work/actual/actual/packages/loot-core/src/client/reducers/prefs.ts 📈 +490 B (+85.81%) 571 B → 1.04 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/AppliedFilters.js 20.96 kB → 21.01 kB (+52 B) +0.24%

Smaller

Asset File Size % Changed
static/js/index.js 3.32 MB → 3.25 MB (-72.65 kB) -2.14%
static/js/ReportRouter.js 1.5 MB → 1.49 MB (-16.49 kB) -1.07%
static/js/narrow.js 82.55 kB → 77.58 kB (-4.97 kB) -6.02%
static/js/wide.js 225.75 kB → 222.51 kB (-3.24 kB) -1.44%
static/js/usePreviewTransactions.js 1.64 kB → 1.59 kB (-48 B) -2.86%

Unchanged

Asset File Size % Changed
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%

Copy link
Contributor

github-actions bot commented Aug 15, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.19 MB → 1.19 MB (-441 B) -0.04%
Changeset
File Δ Size
packages/loot-core/src/server/budget/rollover.ts 🆕 +6.05 kB 0 B → 6.05 kB
node_modules/@rschedule/json-tools/es2015/Schedule.js 🆕 +3.24 kB 0 B → 3.24 kB
node_modules/@rschedule/json-tools/es2015/main.js 🆕 +1.34 kB 0 B → 1.34 kB
packages/loot-core/src/server/util/rschedule.ts 📈 +41 B (+23.30%) 176 B → 217 B
packages/loot-core/src/server/prefs.ts 📈 +387 B (+18.93%) 2 kB → 2.37 kB
packages/loot-core/src/server/rules/app.ts 📈 +148 B (+4.24%) 3.41 kB → 3.55 kB
packages/loot-core/src/server/accounts/rules.ts 📈 +864 B (+2.81%) 30.08 kB → 30.92 kB
packages/loot-core/src/server/accounts/transaction-rules.ts 📈 +224 B (+0.78%) 27.9 kB → 28.12 kB
packages/loot-core/src/server/schedules/app.ts 📈 +125 B (+0.72%) 16.89 kB → 17.02 kB
packages/loot-core/src/server/schedules/find-schedules.ts 📈 +62 B (+0.53%) 11.35 kB → 11.42 kB
packages/loot-core/src/platform/server/sqlite/index.web.ts 📉 -6 B (-0.11%) 5.38 kB → 5.37 kB
packages/loot-core/src/server/budget/base.ts 📉 -30 B (-0.20%) 14.95 kB → 14.92 kB
packages/loot-core/src/server/dashboard/app.ts 📉 -33 B (-0.44%) 7.35 kB → 7.32 kB
packages/loot-core/src/server/aql/schema/index.ts 📉 -74 B (-0.50%) 14.6 kB → 14.52 kB
packages/loot-core/src/server/main.ts 📉 -427 B (-0.68%) 61.37 kB → 60.96 kB
packages/loot-core/src/server/sync/index.ts 📉 -208 B (-0.86%) 23.48 kB → 23.28 kB
packages/loot-core/src/server/sheet.ts 📉 -60 B (-0.87%) 6.72 kB → 6.66 kB
packages/loot-core/src/shared/errors.ts 📉 -35 B (-0.89%) 3.84 kB → 3.81 kB
packages/loot-core/src/server/accounts/sync.ts 📉 -282 B (-1.15%) 24.05 kB → 23.77 kB
packages/loot-core/src/shared/months.ts 📉 -189 B (-1.58%) 11.71 kB → 11.52 kB
packages/loot-core/src/server/budget/goals/goalsSchedule.ts 📉 -137 B (-1.80%) 7.45 kB → 7.32 kB
packages/loot-core/src/shared/util.ts 📉 -229 B (-2.12%) 10.54 kB → 10.32 kB
packages/loot-core/src/server/budget/statements.ts 📉 -28 B (-2.67%) 1.02 kB → 1021 B
packages/loot-core/src/server/migrate/migrations.ts 📉 -147 B (-3.24%) 4.44 kB → 4.29 kB
packages/loot-core/src/server/db/index.ts 📉 -659 B (-3.36%) 19.13 kB → 18.49 kB
packages/loot-core/src/shared/rules.ts 📉 -673 B (-7.01%) 9.38 kB → 8.72 kB
packages/loot-core/src/server/notes/app.ts 📉 -31 B (-12.65%) 245 B → 214 B
packages/loot-core/src/server/budget/actions.ts 📉 -1.72 kB (-14.35%) 12.01 kB → 10.29 kB
packages/loot-core/src/platform/server/fetch/index.web.ts 📉 -629 B (-94.16%) 668 B → 39 B
packages/loot-core/src/server/budget/envelope.ts 🔥 -6.05 kB (-100%) 6.05 kB → 0 B
packages/loot-core/migrations/1723665565000_prefs.js 🔥 -1.33 kB (-100%) 1.33 kB → 0 B
packages/loot-core/src/server/preferences/app.ts 🔥 -363 B (-100%) 363 B → 0 B
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
kcab.worker.js 1.19 MB → 1.19 MB (-441 B) -0.04%

Unchanged

No assets were unchanged

@psybers
Copy link
Contributor Author

psybers commented Aug 15, 2024

Still needs work...

image

@psybers
Copy link
Contributor Author

psybers commented Aug 15, 2024

Trying an alternate approach. Seems to get farther, but getting an error loading one of the modules (which breaks the main window's thread):

image

One other issue. I couldn't figure out how to access localStorage, so for now it is hard coding to 'en' locale.

Copy link
Contributor

github-actions bot commented Sep 3, 2024

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Sep 3, 2024
@github-actions github-actions bot removed the Stale label Sep 4, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added Stale and removed Stale labels Sep 11, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Sep 19, 2024
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The pull request introduces internationalization (i18n) support in the Electron application by integrating the i18next library and its backend. It modifies multiple files to implement dynamic translation for menu labels and expands the input paths for localization. Additionally, it updates the ESLint configuration to ignore build directories, ensuring that generated files are excluded from linting checks. New dependencies are added to the package.json, and a new file for i18n functionality is created. The changes also include the integration of the i18next backend for managing translations and enhancing the user interface for multilingual support.

Changes

Files Change Summary
.eslintignore Added packages/desktop-electron/build/ to ignore list.
packages/desktop-client/i18next-parser.config.js Modified to include an additional input path for the i18next parser.
packages/desktop-electron/i18n.ts, packages/desktop-electron/index.ts, packages/desktop-electron/menu.ts Implemented i18n functionality, including dynamic translation for menu labels and integration with the i18next library.
packages/desktop-electron/package.json Added dependencies: i18next, i18next-electron-fs-backend, lodash, and @types/lodash.
packages/desktop-electron/preload.ts Exposed i18nextElectronBackend via contextBridge for accessing i18next functionality in the main world context.

Possibly related PRs

  • Marked files for translation #3444: This PR focuses on marking files for translation, which relates to the internationalization changes made in the main PR, particularly in the context of enhancing language support in the application.
  • ♻️ (synced-prefs) separate metadata and local prefs out #3458: This PR introduces internationalization support in the FinancesApp.tsx file, which aligns with the internationalization efforts seen in the main PR, specifically regarding the integration of translation functionalities.
  • :electron: Reduce electron package size #3553: Although primarily focused on reducing package size, this PR also involves changes to the packages/desktop-electron directory, which is relevant to the main PR's modifications in the same directory, particularly concerning the integration of internationalization features.

Suggested labels

:sparkles: Merged

Suggested reviewers

  • MikesGlitch
  • joel-jeremy

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b3669b3 and 54cd752.

Files ignored due to path filters (2)
  • upcoming-release-notes/3267.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (7)
  • .eslintignore (1 hunks)
  • packages/desktop-client/i18next-parser.config.js (1 hunks)
  • packages/desktop-electron/i18n.ts (1 hunks)
  • packages/desktop-electron/index.ts (4 hunks)
  • packages/desktop-electron/menu.ts (11 hunks)
  • packages/desktop-electron/package.json (2 hunks)
  • packages/desktop-electron/preload.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • .eslintignore
Additional context used
GitHub Check: lint
packages/desktop-electron/i18n.ts

[warning] 27-27:
Prefer named exports

Additional comments not posted (9)
packages/desktop-electron/preload.ts (1)

19-19: Review security implications of exposing process to the renderer

Exposing the process object via backend.preloadBindings(ipcRenderer, process) can introduce security risks. Verify that this exposure is necessary and that it complies with Electron's security best practices to prevent potential vulnerabilities.

Consider whether all required functionalities can be achieved without exposing the entire process object to the renderer process.

packages/desktop-electron/package.json (1)

93-94: Internationalization dependencies added successfully

The addition of "i18next" and "i18next-electron-fs-backend" is appropriate for implementing internationalization support in the Electron application.

packages/desktop-electron/menu.ts (3)

264-281: Ensure Reliability When Modifying the 'Window' Menu

When modifying the 'Window' menu, you are locating it using template.findIndex(t => t.role === 'window'), which is reliable due to the static role. However, ensure that any additional modifications do not rely on translated labels to prevent similar issues.


9-9: Verify Proper Initialization of the i18n Module

Ensure that the i18n module imported from './i18n' is properly initialized before being used. An uninitialized translation module could lead to untranslated labels or runtime errors.


209-209: Confirm Conditional Inclusion of the 'Screenshot' Menu Item

The 'Screenshot' menu item is conditionally included based on the isDev flag. Verify that this item is appropriately excluded from production builds to prevent unintended exposure of development tools.

packages/desktop-electron/index.ts (2)

118-118: Integration of backend.mainBindings is correct

The call to backend.mainBindings(ipcMain, win, fs); successfully sets up the i18n backend in the main process, enabling translation functionality within the Electron application.


277-277: Proper cleanup with backend.clearMainBindings

Calling backend.clearMainBindings(ipcMain); ensures that i18n bindings are properly cleared when all windows are closed on macOS, preventing potential memory leaks or dangling references.

packages/desktop-electron/i18n.ts (2)

6-7: Verify Relative Paths for Translation Files

The loadPath and addPath are using relative paths that may not resolve correctly in the Electron environment, especially when packaging the application. Ensure that these paths correctly point to your translation files at runtime.

Consider modifying the paths to use __dirname for accurate resolution:

-    loadPath: '../desktop-client/locale/{{lng}}.json',
-    addPath: '../desktop-client/locale/{{lng}}.missing.json',
+    loadPath: path.join(__dirname, 'locale', '{{lng}}.json'),
+    addPath: path.join(__dirname, 'locale', '{{lng}}.missing.json'),

Don't forget to import the path module at the beginning of your file:

+import path from 'path';

23-23: Re-evaluate Disabling Value Escaping in Interpolations

Setting escapeValue: false disables HTML escaping during interpolation, which can lead to security risks like XSS attacks if any untrusted data is interpolated.

Ensure that all interpolated values in your translations are from trusted sources. If there's any chance untrusted data could be used, consider setting escapeValue to true:

     interpolation: {
-      escapeValue: false,
+      escapeValue: true,
     },

input: [
'src/**/*.{js,jsx,ts,tsx}',
'../loot-core/src/**/*.{js,jsx,ts,tsx}',
'../desktop-electron/*.{js,ts}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include subdirectories in the input path for comprehensive localization

The current input path '../desktop-electron/*.{js,ts}' only includes JavaScript and TypeScript files located directly in the ../desktop-electron/ directory. To ensure that all relevant files, including those in subdirectories, are processed for translation keys, consider updating the pattern to include subdirectories.

Apply this diff to update the input path:

-      '../desktop-electron/*.{js,ts}',
+      '../desktop-electron/**/*.{js,ts}',
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'../desktop-electron/*.{js,ts}',
'../desktop-electron/**/*.{js,ts}',

@@ -6,6 +6,8 @@ import {
SaveFileDialogPayload,
} from './index';

const backend = require('i18next-electron-fs-backend');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import instead of CommonJS require

For consistency and better TypeScript integration, consider importing i18next-electron-fs-backend using ES6 import syntax. This enhances type checking and aligns the code with modern standards.

Suggested change:

-const backend = require('i18next-electron-fs-backend');
+import backend from 'i18next-electron-fs-backend';

Ensure that the module exports support this syntax, and adjust the import statement if necessary.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const backend = require('i18next-electron-fs-backend');
import backend from 'i18next-electron-fs-backend';

@@ -90,6 +90,9 @@
"dependencies": {
"electron-is-dev": "2.0.0",
"electron-log": "4.4.8",
"i18next": "^23.12.6",
"i18next-electron-fs-backend": "^3.0.2",
"lodash": "^4.17.21",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider optimizing lodash usage

Adding "lodash" introduces a large dependency that can increase the application's size. If only a few utility functions are needed, consider importing specific modules (e.g., "lodash.merge") or using native JavaScript alternatives to minimize the bundle size.

@@ -98,6 +101,7 @@
"@electron/notarize": "2.4.0",
"@electron/rebuild": "3.6.0",
"@types/copyfiles": "^2",
"@types/lodash": "^4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align TypeScript definitions with lodash version

The @types/lodash package is specified with "^4". To ensure compatibility and prevent potential type mismatches, consider specifying the exact version to match the "lodash" version "^4.17.21".

Apply this diff to update the @types/lodash version:

     "@types/copyfiles": "^2",
-    "@types/lodash": "^4",
+    "@types/lodash": "^4.17.21",
     "copyfiles": "^2.4.1",

Committable suggestion was skipped due to low confidence.

@@ -238,13 +240,13 @@ export function getMenu(
],
});
// Edit menu.
const editIdx = template.findIndex(t => t.label === 'Edit');
const editIdx = template.findIndex(t => t.label === i18n.t('Edit'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Issue with Using Translated Labels in findIndex

Using i18n.t('Edit') within template.findIndex may lead to issues if the translation of 'Edit' changes or differs across languages. This could result in editIdx being -1, causing a runtime error when accessing template[editIdx].

Consider assigning a unique identifier to the 'Edit' menu item to reliably locate it, regardless of language.

Apply this diff to fix the issue:

 {
   label: i18n.t('Edit'),
+  id: 'edit-menu',
   submenu: [
     // submenu items...
   ],
 },
 // Later in the code, find the 'Edit' menu using the id
-const editIdx = template.findIndex(t => t.label === i18n.t('Edit'));
+const editIdx = template.findIndex(t => t.id === 'edit-menu');

Committable suggestion was skipped due to low confidence.

Comment on lines +201 to 202
const tools = menu.items.filter(item => item.label === i18n.t('Tools'))[0];
tools.submenu?.items.forEach(item => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using translated labels for menu item identification

Filtering menu items using i18n.t('Tools') can cause identification issues when the language changes. Assign unique identifiers to menu items to ensure reliable access regardless of the current language setting.

Suggested refactor:

Assign an id to the "Tools" menu item:

{
  label: i18n.t('Tools'),
  id: 'menu-tools',
  // ...
},

Update the reference in your code:

-const tools = menu.items.filter(item => item.label === i18n.t('Tools'))[0];
+const tools = menu.getMenuItemById('menu-tools');

Comment on lines +206 to +211
const edit = menu.items.filter(item => item.label === i18n.t('Edit'))[0];
const editItems = edit.submenu?.items || [];
editItems
.filter(item => item.label === 'Undo' || item.label === 'Redo')
.filter(
item => item.label === i18n.t('Undo') || item.label === i18n.t('Redo'),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using translated labels for menu item identification

Using i18n.t('Edit'), i18n.t('Undo'), and i18n.t('Redo') for filtering can become unreliable with different languages. Assign unique identifiers to these menu items to maintain consistent behavior.

Suggested refactor:

Assign ids to the relevant menu items:

{
  label: i18n.t('Edit'),
  id: 'menu-edit',
  submenu: [
    {
      label: i18n.t('Undo'),
      id: 'menu-undo',
      // ...
    },
    {
      label: i18n.t('Redo'),
      id: 'menu-redo',
      // ...
    },
    // ...
  ],
},

Update your filtering logic:

-const edit = menu.items.filter(item => item.label === i18n.t('Edit'))[0];
+const edit = menu.getMenuItemById('menu-edit');

- editItems.filter(
-   item => item.label === i18n.t('Undo') || item.label === i18n.t('Redo'),
- )
+ editItems.filter(
+   item => item.id === 'menu-undo' || item.id === 'menu-redo',
+ )

import { getMenu } from './menu';
import {
get as getWindowState,
listen as listenToWindowState,
} from './window-state';

import './security';
const backend = require('i18next-electron-fs-backend');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import instead of require for module consistency

To maintain consistency and leverage TypeScript's features, consider replacing require with an import statement. This ensures better type checking and aligns with modern ES6 module syntax.

Apply this diff:

-const backend = require('i18next-electron-fs-backend');
+import backend from 'i18next-electron-fs-backend';

If i18next-electron-fs-backend does not have a default export or if there are compatibility issues, you might need to adjust the import:

-const backend = require('i18next-electron-fs-backend');
+import * as backend from 'i18next-electron-fs-backend';

Ensure that your tsconfig.json has "esModuleInterop": true if you're using default imports with CommonJS modules.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const backend = require('i18next-electron-fs-backend');
import backend from 'i18next-electron-fs-backend';

Comment on lines +14 to +15
lng: 'en', // FIXME localStorage undefined
// lng: localStorage.getItem('language') || 'en',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot Access localStorage in the Main Process

localStorage is a Web API available in the renderer process, not in the main process of an Electron application. Attempting to access it in the main process results in undefined.

To resolve this, consider the following options:

  • Option 1: Use Electron's ipcMain and ipcRenderer modules to communicate the language preference from the renderer process to the main process.

  • Option 2: Store the language preference in a configuration file using Electron's app.getPath('userData') directory.

Here's how you might implement Option 1:

  1. In your renderer process, send the language preference to the main process:

    // renderer.js
    const { ipcRenderer } = require('electron');
    ipcRenderer.send('set-language', localStorage.getItem('language') || 'en');
  2. In the main process, listen for the language setting and initialize i18n accordingly:

    +import { ipcMain } from 'electron';
    
     let language = 'en'; // default language
    
    +ipcMain.on('set-language', (event, lng) => {
    +  language = lng;
    +  i18n.changeLanguage(language);
    +});
    
     i18n.use(backend).init({
        // ...
    -   lng: 'en', // FIXME localStorage undefined
    +   lng: language,
        // ...
     });

},
});

export default i18n;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer Named Exports Over Default Export

Using named exports can improve maintainability and enable easier refactoring and code navigation.

Change the default export to a named export:

-export default i18n;
+export { i18n };

And update any import statements accordingly:

-import i18n from './i18n';
+import { i18n } from './i18n';
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default i18n;
export { i18n };
Tools
GitHub Check: lint

[warning] 27-27:
Prefer named exports

@github-actions github-actions bot removed the Stale label Oct 15, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Oct 22, 2024
@github-actions github-actions bot removed the Stale label Oct 23, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Oct 30, 2024
@github-actions github-actions bot removed the Stale label Oct 31, 2024
Copy link
Contributor

github-actions bot commented Nov 8, 2024

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Nov 8, 2024
@github-actions github-actions bot removed the Stale label Nov 9, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Nov 16, 2024
@github-actions github-actions bot removed the Stale label Nov 17, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Nov 24, 2024
@github-actions github-actions bot removed the Stale label Nov 25, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Dec 2, 2024
@github-actions github-actions bot removed the Stale label Dec 3, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Dec 10, 2024
@github-actions github-actions bot removed the Stale label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant